#pragma once

#include <iostream>
#include <cstring>
#include <string>
#include <sys/types.h>
#include <arpa/inet.h>

class InetAddr
{
public:
    InetAddr(sockaddr_in addr)
        : _addr(addr)
    {
        _port = addr.sin_port;
        _ip = inet_ntoa(addr.sin_addr);
    }

    std::string StringAddr()
    {
        return _ip + ": " + std::to_string(_port);
    }

    const struct sockaddr_in &NetAddr() { return _addr; }

    std::string Ip() { return _ip; }
    uint16_t Port() { return _port; }

    bool operator==(const InetAddr &addr)
    {
        return addr._ip == _ip && addr._port == _port;
    }

private:
    sockaddr_in _addr;
    std::string _ip;
    uint16_t _port;
};